package com.qining618.cms.cms.service.impl;

import com.qining618.cms.cms.domain.ChannelContent;
import com.qining618.cms.cms.mapper.ChannelContentMapper;
import com.qining618.cms.cms.service.ChannelContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qining618.common.exception.BusinessException;
import com.qining618.common.result.ErrorCode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * CMS栏目内容关联表 服务实现类
 * </p>
 *
 * @author qining
 * @date 2019-09-17
 */
@Transactional(readOnly = true, rollbackFor = Exception.class)
@Service
public class ChannelContentServiceImpl extends ServiceImpl<ChannelContentMapper, ChannelContent> implements ChannelContentService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteByContentId(Long contentId) {
        this.baseMapper.deleteByChannelId(contentId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ChannelContent save(Long channelId, Long contentId) {
        ChannelContent channelContent = new ChannelContent();
        channelContent.setChannelId(channelId).setContentId(contentId);
        int opNum = this.baseMapper.insert(channelContent);
        if (opNum != 1) {
            throw new BusinessException(ErrorCode.DB_ERROR);
        }
        return channelContent;
    }
}
